/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.documents.main.action;

import com.documents.common.core.PageBean;
import com.documents.common.core.action.BaseActionSupport;
import com.documents.pojo.Users;
import com.documents.service.users.UserService;
import org.apache.struts2.interceptor.ServletRequestAware;

/**
 *
 * @author Administrator
 */
public class UsersAction extends BaseActionSupport implements ServletRequestAware {

    private UserService userService;
    private Users user;
    private int page = 1;
    private PageBean pageBean;
    private int pageSize = 20;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public PageBean getPageBean() {
        return pageBean;
    }

    public void setPageBean(PageBean pageBean) {
        this.pageBean = pageBean;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public String list() {

        pageBean = userService.queryForPage(pageSize, page, user);

        return SUCCESS;
    }

    public String show() {
        if (user.getId() != null) {
            user = userService.get(user.getId());
        }

        return SUCCESS;
    }

    public String del() {
        if (user.getId() != null) {
            userService.delById(user.getId());
            return SUCCESS;
        }
        return ERROR;
    }

    public String update() {
        String newpwd = user.getPassword();
        if (user.getId() != null) {
            user = userService.get(user.getId());
            user.setPassword(newpwd);
            userService.update(user);
        }


        return SUCCESS;
    }
}
